package com.agnes.okhttp.lib.callback;

import android.app.Activity;

import com.agnes.okhttp.lib.NetConst;

import org.json.JSONArray;
import org.json.JSONObject;

public abstract class JACallback extends QkBaseCallback {


    public JACallback(Activity context) {
        super(context);
    }

    public JACallback(Activity context, boolean showLoading) {
        super(context, showLoading);
    }

    @Override
    protected int emptyFlag() {
        return NetConst.FLAG_JO;
    }

    @Override
    protected void parseResult(JSONObject rootJson) {

        int code = rootJson.optInt(NetConst.CODE);
        String msg = rootJson.optString(NetConst.MESSAGE);
        JSONArray dataJson = rootJson.optJSONArray(NetConst.DATA);

        if (NetConst.SUCCESS_CODE == code) {
            onSuccess(msg, dataJson);
        } else {
            onFail(code, msg, dataJson);
        }

    }

    /**
     * 开发者重写
     *
     * @param code     0 以外的错误码
     * @param msg      错误信息
     * @param dataJson dataJson
     */
    public void onFail(int code, String msg, JSONArray dataJson) {

    }

    public abstract void onSuccess(String msg, JSONArray dataJson);


}
